// 租客管理接口文档
import { api } from 'boot/axios'

/** 新增用户数：
 * name	String	是	租客姓名
 * idNumber	String	是	身份证号码
 * phoneNumber	String	是	联系电话
 * houseNumber	String	是	房屋编号
 * address	String	是	房屋地址
 * rent	BigDecimal	是	租金金额
 * leaseStartDate	LocalDateTime	是	租赁开始日期
 * leaseEndDate	LocalDateTime	是	租赁结束日期
 * overdueNumber	Integer	否	逾期次数
 * contract	String	否	合同链接
 **/
export interface ITenantParam {
  name: string
  idNumber: string
  phoneNumber: string
  houseNumber: string
  address: string
  rent: number | string
  leaseStartDate: string
  leaseEndDate: string
  contract: string
}
export type IEditTenantParam = Partial<ITenantParam> & {
  tenantId: number | string
}

const TENANT_URL = '/house/tenant'
const TENANT_PAGE_URL = '/house/tenant/page'
const TENANT_LIST_URL = '/house/tenant/list'

// Tenant
export function addTenant(data: ITenantParam) {
  return api.post(TENANT_URL, data)
}
export function editTenant(data: IEditTenantParam) {
  return api.put(TENANT_URL, data)
}
export function removeTenant(id: number) {
  return api.delete(`${TENANT_URL}/${id}`)
}
export function getTenantById(id: number) {
  return api.get(`${TENANT_URL}/${id}`)
}
export function getTenantList() {
  return api.get(TENANT_LIST_URL)
}
export interface ITenantQueryParams {
  pageNum: number
  pageSize: number
  houseNumber?: string
}
export function getTenantPageList(oArg: ITenantQueryParams) {
  const params: ITenantQueryParams = { pageNum: oArg.pageNum || 1, pageSize: oArg.pageSize || 10 }
  if (oArg.houseNumber) {
    params.houseNumber = oArg.houseNumber
  }
  return api.get(TENANT_PAGE_URL, { params })
}
